/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import Server.BUS.QueryUlti;
import Server.BUS.StringUlti;
import Server.DTO.Query;
import org.junit.*;
import static org.junit.Assert.*;

/**
 *
 * @author Trung
 */
public class QueryUltiTest {
    
    public QueryUltiTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }

    /**
     * Test of checkQueryType method, of class QueryUlti.
     */
    @Test
    public void testCheckQueryType1() {
        String queryString = "SELECT * FROM TableA";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("SELECT_NOWHERE"));
    }
    
    @Test
    public void testCheckQueryType2() {
        String queryString = "SELECT * FROM TableA WHERE id = 3";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("SELECT_HAVEWHERE"));
    }
    
    @Test
    public void testCheckQueryType3() {
        String queryString = "INSERT INTO TableA VALUES(3, \"abc\")";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("INSERT"));
    }
    
//    @Test
//    public void testCheckQueryType4() {
//        String queryString = "Insert into TableA Values(3, \"abc\") where id = 2";
//        queryString = StringUlti.formatString(queryString);
//        
//        String queryType = QueryUlti.checkQueryType(queryString);
//        assertTrue(queryType.equalsIgnoreCase("INSERT_HAVEWHERE"));
//    }
    
    @Test
    public void testCheckQueryType5() {
        String queryString = "DELETE FROM TableA";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("DELETE_NOWHERE"));
    }
    
    @Test
    public void testCheckQueryType6() {
        String queryString = "DELETE FROM TableA WHERE id = 3";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("DELETE_HAVEWHERE"));
    }
    
    @Test
    public void testCheckQueryType7() {
        String queryString = "UPDATE TableA SET address = 'abc'";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("UPDATE_NOWHERE"));
    }
    
    @Test
    public void testCheckQueryType8() {
        String queryString = "UPDATE TableA SET address = 'abc' WHERE id = 5";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("UPDATE_HAVEWHERE"));
    }
    
    @Test
    public void testCheckQueryType4() {
        String queryString = "abc UPDATE TableA SET address = 'abc' WHERE id = 5";
        queryString = StringUlti.formatString(queryString);
        
        String queryType = QueryUlti.checkQueryType(queryString);
        assertTrue(queryType.equalsIgnoreCase("INVALID_QUERY"));
    }
}
